
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using mfe.lib.data;

namespace mfe.bll
{
	public partial class ItemRelated
	{
        public static bool Delete(string ItemGuidID, string RelatedItemGuidID)
        {
            try
            {
                mfe.lib.data.Database db = mfe.lib.data.DatabaseFactory.CreateDatabase();
                DbCommand cmd = db.GetSqlStringCommand("delete from ItemRelated where ItemGuidID=@ItemGuidID and RelatedItemGuidID=@RelatedItemGuidID");
                db.AddInParameter(cmd, "ItemGuidID", DbType.String, ItemGuidID);
                db.AddInParameter(cmd, "RelatedItemGuidID", DbType.String, RelatedItemGuidID);
                db.ExecuteNonQuery(cmd);
                return true;
            }
            catch (Exception ex)
            {
                mfe.lib.Logger.Log(ex);
                return false;
            }
        }

        public static List<ItemRelated> ItemRelatedCollection(string itemGuidID)
        {
            List<ItemRelated> retval = new List<ItemRelated>();
            ///TODO: implement, get all direct and indirect related items

            //try
            //{
            //    mfe.lib.data.Database db = mfe.lib.data.DatabaseFactory.CreateDatabase();
            //    DbCommand cmd = db.GetSqlStringCommand(sql);
            //    IDataReader reader = db.ExecuteReader(cmd);
            //    while (reader.Read())
            //    {
            //        ItemRelated obj = new ItemRelated();
            //        _SetupProperties(reader, obj);
            //        retval.Add(obj);
            //    }
            //    reader.Close();
            //    reader.Dispose();
            //}
            //catch (Exception ex)
            //{
            //    mfe.lib.Logger.Log(ex);
            //}

            return retval;
        }
	}
}
